/**
 * create 2017/07/01
 */

var fs = require('fs'); // fs 读取文件
var multer = require('multer'); // 上传图片

var createFolder = function (folder) {
    try {
        fs.accessSync(folder);
    } catch (e) {
        fs.mkdirSync(folder);
    }
};


var uploadFolder = './upload/'; // 上传图片保存目录

createFolder(uploadFolder); // 是否创建文件夹

var storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, uploadFolder);
    },
    filename: function (req, file, cb) {
        cb(null, file.originalname);
    }
});

var upload = multer({ storage: storage });

module.exports =  upload;